//
//  StaticsUtility.m
//  DataCollector
//
//  Created by jiro on 12/07/12.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "StaticsUtility.h"


@implementation StaticsUtility

+ (NSArray*) calcMaWithValues: (NSArray*) values andAverageLength: (int) averageLength
{
	NSMutableArray* array = [ NSMutableArray array ];
	if ( [ values count ] < averageLength )
	{
		return array;
	}

	for ( int i = averageLength - 1, count = [ values count ]; i < count; i++ )
	{
		double value = 0.0;
		for ( int j = 0; j < averageLength; j++ )
		{
			value += [ [ values objectAtIndex: i - j ] doubleValue ];
		}
		value /= averageLength;
		[ array addObject: [ NSNumber numberWithDouble: value ] ];
	}
	return array;
}

@end
